<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 注册</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <!--    <script>if (window.top !== window.self) {-->
    <!--        window.top.location = window.location;-->
    <!--    }</script>-->

</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name"></h1>
            <img class="logo-name" src="img/医生头像.png" height="180px" width="180px"/>
        </div>
        <br/>
        <h3>修改密码</h3>

        <form class="m-t" role="form" action="login.html" style="text-align: left;">

            <div class="form-group">
                <a style="font-size: 15px; color: black;">原密码</a><a style="color: red;">*</a>
                <input type="password" id="oldPassword" class="form-control" placeholder="请输入原密码" required="">
            </div>
            <div class="form-group">
                <a style="font-size: 15px; color: black;">新密码</a><a style="color: red;">*</a>
                <input type="password" id="password" class="form-control" placeholder="请输入密码" required="">
            </div>
            <div class="form-group">
                <input type="password" id="rePassword" class="form-control" placeholder="请再次输入密码" required="">
            </div>


            <br>
            <button type="button" id="submit" onclick="register()" class="btn btn-primary block full-width m-b">确认修改
            </button>

        </form>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<!-- iCheck -->
<!--<script src="js/plugins/iCheck/icheck.min.js"></script>-->
<script src="./js/index.js"></script>
<script>
    // $(document).ready(function () {
    //     $('.i-checks').iCheck({
    //         checkboxClass: 'icheckbox_square-green',
    //         radioClass: 'iradio_square-green',
    //     });
    // });


    function register() {
        var password = $("#password").val().trim();
        var rePassword = $("#rePassword").val().trim();
        var oldpassword = $("#oldPassword").val().trim();
        if (rePassword == null || password == null || rePassword != password) {
            alert("两次密码不一致！");
            return false;
        }
        if (oldpassword == null || password == null || oldpassword == password) {
            alert("新密码与旧密码相同！");
            return false;
        }
        $.ajax({
            async: true,
            type: "post",
            url: "/changePassword",
            data: JSON.stringify(getQueryData()),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    window.location.href = "/login.html";
                    alert(result.RESULT);
                } else {
                    alert(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });
    }


    function getQueryData() {
        var dto = {};
        if (!ifEmpty($("#password").val())) {
            dto["password"] = $("#password").val().trim();
        }
        if (!ifEmpty($("#oldPassword").val())) {
            dto["oldPassword"] = $("#oldPassword").val().trim();
        }
        return dto;
    }


</script>


</body>

</html>
